#ifndef _WAVE_H
#define _WAVE_H

#include "readwave.h"
#include <cmath>

class Wave {
public:

	// constructor with file name
	Wave::Wave(char* fname) {
		filename = new char[strlen(fname)+1];
		strcpy(filename, fname);
		data = ReadAudio(filename, &length, &header);
	}

	~Wave() {
		delete filename;
		delete []data;
	}

	// display information about fs, #bits, #channels
	void ShowHeaderInfo() {
		printf("Sample Rate: %u\n", header.SampleRate);
		printf("NBits: %u\n", header.NBitsPersample);
		printf("Channels: %u\n", header.NChannels);
		printf("Samples: %u\n", header.RawDataFileLength);
	}

	// check if the audio satisfies: 16kHz sampling, 16 bits and mono
	bool CheckHeaderInfo() {
		if (header.SampleRate != 16000) {
			return false;
		}
		if (header.NBitsPersample != 16) {
			return false;
		}
		if (header.NChannels != 1) {
			return false;
		}
		return true;
	}

	// input a duration in millisec, output a length in sample
	unsigned long Time2Sample(double duration) {
		return (unsigned long) duration * header.SampleRate / 1000;
	}

	char* filename;	// file name
	short* data;	// the array of audio data
	int length;		// number of samples in audio data
	WavHead header;	// for fs/nbits/nchannel information
};

#endif